#!/usr/bin/perl

use lib::abs qw( .. );
use JIP::ToolSet; # load my commonly-used modules in a single import

use Readonly qw( Readonly );
use English qw( -no_match_vars );
use Test::More tests => 13;

Readonly my $PATH_TO_CONFIG => './my_conf.pm';

use_ok('Configurator');
require_ok('Configurator');

can_ok( 'Configurator', qw( new getSettings ) );

{
    my $conf = Configurator->new( conf => $PATH_TO_CONFIG );

    isa_ok( $conf, 'Configurator' );
    isa_ok( $conf, 'Class::Base' );

    my $CONF = $conf->getSettings;

    is( $CONF->main->logs,         'tratata', '->main->log' );
    is( $CONF->{'main'}->{'logs'}, 'tratata', '->{main}->{log}' );
    is( $CONF->SQL->user,          'jip',     '->SQL->user' );

    is( $CONF->tratata, undef, '->tratata' );

    is( $CONF->main->utf, 'тратата', 'unicode' );
}

{
    my $conf;

    try {
        $conf = Configurator->new;
    }
    catch {
        like(
            $ARG,
            qr/^required parameter "conf" not defined at /,
            'error handler 1'
        );
    };

    is( $conf, undef, 'empty class' );
}

{
    my $conf;

    try {
        $conf = Configurator->new( conf => 'incorrect path to file' );
    }
    catch {
        like( $ARG, qr/^no such file at /, 'error handler 2' );
    };
}
